import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './interceptor/httpException';
import { TransformInterceptor } from './interceptor/transform.interceptor';
import { NestExpressApplication } from '@nestjs/platform-express';
import rateLimit from 'express-rate-limit'
import * as bodyParser from 'body-parser';
import { Logger } from '@nestjs/common';
const helmet = require("helmet");


const hostname = process.env.IP || "127.0.0.1"
const port = process.env.PORT || 3000

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalInterceptors(new TransformInterceptor());
  app.use(helmet())
  app.use(bodyParser.json({limit: '50mb'}));
  app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
  Logger.log('路径=')
  Logger.log(__dirname)
  Logger.log('---------------')
  //15分钟同一个ip产生100个请求
  // app.use(
  //   rateLimit({
  //     windowMs: 1 * 60 * 1000, // 1 minutes
  //     max: 1000 * 1000, // limit each IP to 1000 requests per windowMs
  //   }),
  // )
  // app.set('trust proxy', true);
  await app.listen(port);
}
bootstrap();
